import _ from 'lodash';
import fs from 'fs';
import path from 'path';
import nock from 'nock';
import Promise from 'bluebird';
import 'babel-polyfill';

import knex from 'knex';
import knexConfigs from '../knexfile';
const knexConfig = knexConfigs['development'];
const db = knex(knexConfig);

/**
 * Add global hooks
 */
function deleteAllTables() {
}

// before(function() {
//   this.timeout(300000); // eslint-disable-line no-invalid-this

//   return deleteAllTables()
//   .then(() => db.migrate.latest())
//   .then(() => db.seed.run())
//   .then(() => {
//     injectKnex();
//   });
// });

after(function(){
  db.destroy();
});

beforeEach(function() {
  // Allow more time for seed reloading
  this.timeout(10000); // eslint-disable-line no-invalid-this
  // Reload the seed data into the test database
  return db.seed.run();
});

afterEach(function() {
  // Make sure to clean all nock mocks
  nock.cleanAll();
});

/**
 * Load tests
 */
// for (const testType of ['services']) {
//   const testsPath = __dirname;
//   for (const testFile of fs.readdirSync(path.join(testsPath, testType))) {
//     if (testFile.endsWith('_test.js')) {
//       require(`./${testType}/${testFile}`);
//     }
//   }
// }
